#!/bin/bash
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
while getopts ":r:u:p:" opt; do
	case $opt in
		r) REPO_URL="$OPTARG"
		;;
		u) USERNAME="$OPTARG"
		;;
		p) PASSWORD="$OPTARG"
		;;
	esac
done

# Find and upload files
find . -type f -not -path './mavenimport.sh*' -not -path '*/\.*' \
    -not -path '*/^archetype-catalog.xml*' \
    -not -path '*/^maven-metadata-local.xml' \
    -not -path '*/^maven-metadata-deployment.xml' -print0 | \
    xargs -0 -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} "${REPO_URL}/{}" || {
        echo "Error uploading file: {}"
    }

# 使用前 将其放到repository文件夹下 chmod 755 push2Nexus.sh
# push2Nexus.sh -u Nexus账号 -p Nexus密码 -r http://www.baidu.com/repository/devops-test-releases/